/**
 *
 *  LoginFilter.h
 *
 */

#pragma once

#include <drogon/HttpFilter.h>
#include <drogon/HttpController.h>
#include <drogon/orm/RestfulController.h>

using namespace drogon;
using namespace drogon::orm;
using namespace drogon::nosql;


class LoginFilter : public HttpFilter<LoginFilter> {
  public:
    LoginFilter() {}
    
    /**
     * @brief 验证是否登入
     * @param  req              请求
     * @param  fcb              不成功调用
     * @param  fccb             成功调用
     * 
     * !使用请求内的json数据进行验证：user_id、token.
     */
    virtual void doFilter(const HttpRequestPtr& req,
                          FilterCallback&&      fcb,
                          FilterChainCallback&& fccb) override;

    nosql::RedisClientPtr getRedisClient()
    {
        return drogon::app().getFastRedisClient(redisClientName_);
    }

  protected:
    const std::string redisClientName_{"default"};
};
